package com.sunrise.visual.frame.component
{
	import flash.display.DisplayObject;
	
	import mx.containers.Canvas;
	import mx.containers.VBox;
	import mx.controls.Label;

	[Style(name="titleFontSize", type="Number", format="Length", inherit="no")]
	[Style(name="titleColor", type="uint", format="Color", inherit="no")]
	[Style(name="titleFontFamily", type="String", inherit="no")]
	public class GroupBox extends VBox
	{
		public function GroupBox()
		{
		}
		
		private var txtTitle:Label;
		
		private var _title:String;
		
		private var body:Canvas;
		
		public function get title():String{
			return _title;
		}
		private var titleChanged:Boolean = false;
		public function set title(t:String):void{
			titleChanged = true;
			_title = t;
			invalidateProperties();
		}
		
		override protected function createChildren():void {
			if(txtTitle == null) {
				txtTitle = new Label();
				this.addChild(txtTitle);
//				txtTitle.percentHeight = 14;
				txtTitle.maxHeight = 30;
				txtTitle.percentWidth = 100;
				txtTitle.setStyle("fontSize", this.getStyle("titleFontSize"));
				txtTitle.setStyle("textAlign", "center");
				txtTitle.setStyle("fontFamily", this.getStyle("titleFontFamily"));
				txtTitle.setStyle("color", this.getStyle("titleColor"));
			} 
			if(body == null) {
				body = new Canvas();
				body.percentHeight = 100;
				body.percentWidth = 100;
				this.addChild(body);
			}
			super.createChildren();
		}
		
		override protected function commitProperties():void{
			super.commitProperties();
			if(titleChanged) {
				titleChanged = false;
				txtTitle.text = _title
			}
		}
		
		override public function addChild(child:DisplayObject):DisplayObject {
			if(body == child || txtTitle == child) 
				return super.addChild(child);
			else {
				return body.addChild(child);
			}
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject{
			return body.removeChild(child);
		}
		override public function removeAllChildren():void{
			return body.removeAllChildren();
		}
		
	}
}